﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.ProcessManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.ProcessManagement.ProcessDocVMs
{
    public partial class ProcessDocListVM : BasePagedListVM<ProcessDoc_View, ProcessDocSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ProcessDoc_View>> InitGridHeader()
        {
            return new List<GridColumn<ProcessDoc_View>>{
                
                this.MakeGridHeader(x => x.ProcessDoc_Route).SetTitle(@Localizer["Page.工艺路线"].Value),
                this.MakeGridHeader(x => x.ProcessDoc_Op).SetTitle(@Localizer["Page.工序"].Value),
                this.MakeGridHeader(x => x.ProcessDoc_OpCode).SetTitle(@Localizer["Page.工序编号"].Value),
                this.MakeGridHeader(x => x.ProcessDoc_ProductId).SetTitle(@Localizer["Page.产品"].Value),
                this.MakeGridHeader(x => x.ProcessDoc_FileName).SetTitle(@Localizer["Page.文件名称"].Value),
                this.MakeGridHeader(x => x.ProcessDoc_FileType).SetTitle(@Localizer["Page.文件类型"].Value),
                this.MakeGridHeader(x => x.ProcessDoc_RemotePc).SetTitle(@Localizer["Page.远程主机"].Value),
                this.MakeGridHeader(x => x.ProcessDoc_RemotePath).SetTitle(@Localizer["Page.远程主机目录"].Value),
                this.MakeGridHeader(x => x.ProcessDoc_UserName).SetTitle(@Localizer["Page.用户名"].Value),
                this.MakeGridHeader(x => x.ProcessDoc_Pwd).SetTitle(@Localizer["_Admin.Password"].Value),
                 this.MakeGridHeader(x => x.ProcessDoc_Active).SetTitle(@Localizer["Page.激活"].Value),

                this.MakeGridHeader(x => x.ProcessDoc_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ProcessDoc_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ProcessDoc_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ProcessDoc_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ProcessDoc_View> GetSearchQuery()
        {
            var query = DC.Set<ProcessDoc>()

                .CheckEqual(Searcher.RouteId, x => x.RouteId)
                .CheckEqual(Searcher.OpId, x => x.OpId)
                .CheckContain(Searcher.OpCode, x => x.Op.OpCode)
                .CheckEqual(Searcher.ProductId, x => x.ProductId)
                .CheckContain(Searcher.FileName, x => x.FileName)
                .CheckContain(Searcher.FileType, x => x.FileType)
                .CheckContain(Searcher.RemotePc, x => x.RemotePc)
                .CheckContain(Searcher.RemotePath, x => x.RemotePath)
                .CheckContain(Searcher.UserName, x => x.UserName)
                .CheckEqual(Searcher.Pwd, x => x.Pwd)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x => x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x => x.UpdateBy)
                .Select(x => new ProcessDoc_View
                {
                    ID = x.ID,

                    ProcessDoc_Route = x.Route.RoutingCode,
                    ProcessDoc_Op = x.Op.OpCode,
                    ProcessDoc_OpCode = x.OpCode,
                    ProcessDoc_ProductId = x.ProductId,
                    ProcessDoc_FileName = x.FileName,
                    ProcessDoc_FileType = x.FileType,
                    ProcessDoc_RemotePc = x.RemotePc,
                    ProcessDoc_RemotePath = x.RemotePath,
                    ProcessDoc_UserName = x.UserName,
                    ProcessDoc_Pwd = x.Pwd,
                    ProcessDoc_CreateTime = x.CreateTime,
                    ProcessDoc_UpdateTime = x.UpdateTime,
                    ProcessDoc_CreateBy = x.CreateBy,
                    ProcessDoc_UpdateBy = x.UpdateBy,
                    ProcessDoc_Active = x.Active,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ProcessDoc_View: ProcessDoc
    {
        public bool ProcessDoc_Active { get; set; }
        public string ProcessDoc_Route { get; set; }
        public string ProcessDoc_Op { get; set; }
        public string ProcessDoc_OpCode { get; set; }
        public long? ProcessDoc_ProductId { get; set; }
        public string ProcessDoc_FileName { get; set; }
        public string ProcessDoc_FileType { get; set; }
        public string ProcessDoc_RemotePc { get; set; }
        public string ProcessDoc_RemotePath { get; set; }
        public string ProcessDoc_UserName { get; set; }
        public string ProcessDoc_Pwd { get; set; }
        public DateTime? ProcessDoc_CreateTime { get; set; }
        public DateTime? ProcessDoc_UpdateTime { get; set; }
        public string ProcessDoc_CreateBy { get; set; }
        public string ProcessDoc_UpdateBy { get; set; }

    }

}